<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/16 0016
 * Time: 下午 17:31
 */

namespace Admin\Controller;


use Think\Controller;

class LoginController extends Controller
{

    public function index(){


//        dd($_SESSION);
        if ($_POST){
            //获取post提交的登录信息
            $data=I('post.');
       // dump($data);
            //链接数据库并查询数据的信息
            $field=m('user')->find();
//            dump($field['username']);die;
           // $s=$field['password'];

            if ($data['username']!=$field['username']  || md5($data['password'])!=$field['password']){
                $this->error("账号或密码不正确");exit;
            }

//            echo 1;exit;
            $res=$this->check_verify($_POST['code']);
            if(!$res){
                $this->error("验证码错误");exit;
            }
            session('usernameht',$data['username']);


            $this->success('登录成功',u('admin/index/index'));exit;


        }



        $this->display();
    }



    public  function auto(){
        session('name',null);
        $this->success("退出成功",u('admin/login/index'));
    }

    //验证码类
    public function code(){

        $Verify =     new \Think\Verify();
        $Verify->fontSize = 30;
        $Verify->length   = 3;
        $Verify->useNoise = true;
        $Verify->entry();
    }

    public function check_verify($code, $id = ''){
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }
}